import java.util.Collection;
import java.util.Iterator;
import java.util.TreeSet;




public class Library {
private BookSet bs;

Library() {bs = new BookSet();}



Library(Collection books){
	bs = new BookSet();
	bs.addAll(books);
}

public boolean sortedInsert(Book newBook) {
	return bs.add(newBook);
}
			
public Book searchISBN(String isbn){
	Iterator i = bs.iterator();
	Book c;
	Object d;
	while(i.hasNext()){
		d = i.next();
		if (d instanceof Book){
			c =(Book) d;
			if(c.getISBN().equals(isbn))
				return c;
		}
	}
	return null;
}

public Collection searchAuthor(String author){
	Iterator i = bs.iterator();
	TreeSet e = new TreeSet();
	Book c;
	Object d;
	while(i.hasNext()){
		d = i.next();
		if (d instanceof Book){
			c =(Book) d;
			if(c.getAuthor().equals(author))
				e.add(c);
		}
	}
	return e;
}
public String toString(){
	Iterator i = bs.iterator();
	String n = "Library:";
	while (i.hasNext()){
		n +="\n"+ i.next().toString();
	}
	return n;
}

}
